// pages/landmark/landmark.js
import api from '../../utils/api.js'
import { list } from '../../utils/landmark.js'
var app = getApp();
var info = []
import { HTTP } from '../../utils/http.js'
import { config } from '../../utils/config'
let http = new HTTP()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        bannerList: {

        },
        pList: [],
        littleList: [],
        tabs: [{
            id: 0,
            txt: "核心产区农户直发"
        },
        {
            id: 1,
            txt: "手工风味"
        },
        {
            id: 2,
            txt: "最美乡村"
        }
        ],
        current1: 0, // 顶部导航切换
        current2: 0, // 切换省
        current3: 0, // 切换地区
        content: [],
        imgUrl: config.imgUrl,
        show: false, // 显示切换省
    },

    getInfo(obj, url) {
        return new Promise((resolve, reject) => {
            http.request({
                url: url,
                data: obj,
                success: res => {
                    resolve(res);
                }
            })
        })
    },
    change(e) {
        this.setData({
            current1: e.currentTarget.dataset.id
        })
    },
    select(e) {
        let index = e.currentTarget.dataset.idx
        let content = this.data.content
        content.unshift(content.splice(index, 1)[0])
        this.setData({
            content
        })
        this.close()
    },
    close() {
        this.setData({
            show: false
        })
    },
    open() {
        this.setData({
            show: true
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let content = []
        console.log(list)
        list.map(item => {
            item.info.map(item1 => {
                content.push(item1)
            })
        })
        content.unshift(content.splice(9, 1)[0])
        this.setData({
            content
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        wx.wg_util.refreshShopCarBadge();
        list.forEach((ele) => {
            ele.info.forEach((key) => {
                info.push(key)
            })
        })
        this.setData({
            pList: info,
            littleList: info[9].info
        })
        console.log(info)
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})